package org.yxing.palpalgps.adapter;

import java.util.ArrayList;

import org.yxing.palpalgps.R;
import org.yxing.palpalgps.image.ImageCache;
import org.yxing.palpalgps.utils.Helper;
import org.yxing.palpalgps.widget.AsyncImageView;

import android.app.Activity;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery.LayoutParams;
import android.widget.ImageView;

public class PhotoGalleryAdapter extends BaseAdapter {
	
	private ArrayList<String> mData;
	private Activity mActivity;
	
	public PhotoGalleryAdapter (Activity c) {
		mActivity = c;
		mData = new ArrayList<String>();
	}
	
	public PhotoGalleryAdapter(Activity c, ArrayList<String> data) {
		this(c);
		mData.addAll(data);
	}

	@Override
	public int getCount() {
		return mData.size();
	}

	@Override
	public String getItem(int position) {
		return mData.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		AsyncImageView iv = new AsyncImageView(mActivity);
		iv.setDefaultResource(R.drawable.default_avatar);
		iv.setUrl(Helper.getPictureUrl(getItem(position)));
		iv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		iv.setScaleType(ImageView.ScaleType.FIT_START);
		return iv;
	}
	
	public void delete(int position) {
		mData.remove(position);
		notifyDataSetChanged();
	}
}
